//封装分类业务相关代码
import { routeCategoryAPI } from "@/apis/category"
import { onMounted, ref } from "vue"
import { onBeforeRouteUpdate, useRoute } from "vue-router"
export function useCategory() {
    const categoryData = ref({})
    const route = useRoute()

    //  category route
    const getCategory = async (id = route.params.id) => {
        const res = await routeCategoryAPI(id)
        categoryData.value = res.result
    }
    onMounted(() => getCategory())

    onBeforeRouteUpdate((to) => {
        getCategory(to.params.id)
    })
    return {
        categoryData
    }
}